﻿@using CubicFWNet.Data.Models
@using CubicFWNet.Data.ViewModal
@model FinanceInvoice
@{
    var order = ViewBag.Order as Order;
    var customer = ViewBag.Customer as Customer;
    var operationName = ViewBag.OperationName;
    var operationTime = ViewBag.OperationTime;
}
<section class="content-header">
    <h1>
        @if (Model != null)
        {
            if (Model.Status == -1)
            {
                @Html.Raw("开票查询")
            }
            if (Model.Status == 1)
            {
                @Html.Raw("寄票查询")
            }
        }
        &nbsp;
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("ReceivableQuery", "FinanceCost")">应收账款查询</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                @if (Model != null && order != null && customer != null)
                {
                    <form class="form-horizontal" id="frmedit" action="@Url.Action("UpdateFinanceInvoice", "FinanceCost")" method="post">
                        <input type="hidden" id="OrderId" name="OrderId" value="@order.Id" />
                        <input type="hidden" id="Id" name="Id" value="@Model.Id" />
                        <input type="hidden" id="type" name="type" value="1" />
                        <input type="hidden" id="TotalMoney" name="TotalMoney" value="0" />
                        <div class="box-body">
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">订单号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" value="@order.Number" readonly="readonly">
                                </div>
                            </div>
                            @if (!string.IsNullOrEmpty(order.CusNumber) && order.CusNumber.Length > 1)
                            {
                                <div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">客户订单号</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" value="@order.CusNumber" readonly="readonly">
                                    </div>
                                </div>
                            }
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">客户名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="customerName" name="customerName" value="@customer.Name" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">发票号</label>
                                <div class="col-sm-9">
                                    @if (Model.Status == -1)
                                    {
                                        <input type="text" class="form-control" id="Number" name="Number" value="" required>
                                    }
                                    else
                                    {
                                        <input type="text" class="form-control" id="Number" name="Number" value="@Model.Number" readonly="readonly">
                                    }
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6" style="margin-left: 5px;">
                                <label class="col-sm-3 btn btn-primary submitbtn" id="expExcel">导出Excel</label>
                                <div class="col-sm-9">
                                </div>
                            </div>
                            <div id="json-content" class="col-md-12 ">
                                <input type="hidden" id="modalData" value="@Model.ProductData" readonly="readonly">
                                <table class="footable table table-stripped table-bordered table-hover" id="footable">
                                    <thead>
                                        <tr>
                                            <th style="display: none" data-sort-ignore="true">
                                                <input type="hidden" value="客户名称" class="expExa" />
                                            </th>
                                            <th style="display: none" data-sort-ignore="true">
                                                <input type="hidden" value="订单号" class="expExa" />
                                            </th>
                                            <th data-sort-ignore="true">
                                                <input type="hidden" value="品名" class="expExa" />
                                                品名
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                <input type="hidden" value="尺寸宽-mm" class="expExa" />
                                                尺寸宽-mm
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                <input type="hidden" value="尺寸长-mm" class="expExa" />
                                                尺寸长-mm
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                <input type="hidden" value="基本单位" class="expExa" />
                                                基本单位
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true" class="col-md-2">
                                                <input type="hidden" value="数量" class="expExa" />
                                                数量
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true" class="col-md-2">
                                                <input type="hidden" value="价格" class="expExa" />
                                                价格
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                <input type="hidden" value="增值税" class="expExa" />
                                                增值税
                                            </th>
                                            <th data-hide="phone" data-sort-ignore="true" class="col-md-2">
                                                <input type="hidden" value="金额" class="expExa"/>
                                                金额
                                            </th>
                                            <th style="display: none" data-sort-ignore="true">
                                                <input type="hidden" value="对账备注" class="expExa" />
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody id="data-content"></tbody>
                                </table>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">备注</label>
                                <div class="col-sm-9">
                                    @if (Model.Status == -1)
                                    {
                                        <textarea class="form-control" rows="3" placeholder="请输入 ..." name="FinanceInvoiceMemo" id="FinanceInvoiceMemo"></textarea>
                                    }
                                    else
                                    {
                                        <textarea class="form-control" rows="3" placeholder="请输入 ..." name="FinanceInvoiceMemo" id="FinanceInvoiceMemo" readonly="readonly">@Model.FinanceInvoiceMemo</textarea>
                                    }

                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">对账备注</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" rows="3" readonly="readonly" id="InvoiceMemo">@Model.Memo</textarea>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>

                            <div class="form-group col-md-6">
                                <label for="operationName" class="col-sm-3 control-label">操作人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationName" name="operationName" value="@operationName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationTime" class="col-sm-3 control-label">日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" value="@operationTime" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="width: 80%; margin-left: 20px;">
                            @*开票*@
                            @if (Model.Status == -1)
                            {
                                <a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(1)">确认</a>
                            }
                            @*开票后审核（售后模块）*@
                            @if (Model.Status == 1)
                            {
                                <a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(2)">确认</a>
                            }
                            <span id="historyBack" class="btn btn-primary submitbtn">返回</span>
                            @*<a class="btn btn-primary submitbtn" href="@Url.Action("ReceivableQuery", "FinanceCost")">返回</a>*@
                        </div>
                    </form>
                }
            </div>
        </div>
    </div>
</section>

<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@section Scripts{
    <script src="~/Scripts/jquery.table2excel.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    //postData.ProductData = getParam();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            //$.reload();
                            $.modalAlert("操作成功", "success");
                            if (type == 1) {
                                window.location.href = '@Url.Action("ReceivableQuery", "FinanceCost")';
                            }
                            if (type == 2) {
                                window.location.href = '@Url.Action("SendTicketQuery", "CustomerService")';
                            }
                        }
                    });
                }
            });


            var yy = document.getElementById("modalData").value;
            if (yy != "") {
                var data = JSON.parse(document.getElementById("modalData").value);
                var $content = $('#data-content');
                var html = "";
                var totalmoney = 0;
                var customerName = $("#customerName").val();
                var cusNumber = "";
                if ($("#CusNumber").val()) {
                    cusNumber = $("#CusNumber").val();
                }
                var memo = $("#InvoiceMemo").val();
                for (var i = 0; i < data.length; i++) {
                    totalmoney += (data[i].TotalMoney / 1);
                    html += "<tr class='tr'>";
                    html += "<td style='display: none'><input type='hidden' value=" + customerName + " class='expExa' /></td>";
                    html += "<td style='display: none'><input type='hidden' value='" + cusNumber + "' class='expExa' /></td>";
                    html += "<td><input type='hidden' value=" + data[i].ProductName + " class='expExa' />" + data[i].ProductName + "</td>";
                    html += "<td><input type='hidden' value=" + data[i].ProductSizeWidth + " class='expExa' />" + data[i].ProductSizeWidth + "</td>";
                    html += "<td><input type='hidden' value=" + data[i].ProductSizeWidth + " class='expExa' />" + data[i].ProductSizeWidth + "</td>";
                    html += "<td><input type='hidden' value=" + data[i].ProductUnit + " class='expExa' />" + data[i].ProductUnit + "</td>";
                    html += "<td><input type='hidden' value=" + data[i].ProductAmount + " class='expExa' />" + data[i].ProductAmount + "</td>";
                    html += "<td><input type='hidden' value=" + data[i].ProductPrice + " class='expExa' />" + data[i].ProductPrice + "</td>";
                    html += "<td><input type='hidden' value=" + data[i].ProductTax + " class='expExa' />" + data[i].ProductTax + "</td>";
                    html += "<td><input type='hidden' value=" + data[i].TotalMoney + " class='expExa' />" + data[i].TotalMoney + "</td>";
                    html += "<td style='display:none'><input type='hidden' value='" + memo + "' class='expExa' /></td>";
                    html += "</tr>";
                }
                html += "<tr>";
                html += "<td colspan='11'><input type='hidden' value='合计金额" + totalmoney + "' class='expExa' />合计金额：" + totalmoney + "</td>";
                html += "</tr>";
                $("#TotalMoney").val(totalmoney);
                $content.append(html);
            }


            $('#footable').footable();
        });

        var type = 1;

        function formsubmit(t) {
            type = t;
            $("#type").val(t);
            $("#frmedit").submit();
        }

        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });

        $("#expExcel").click(function () {
            $("#footable").table2excel({
                exclude: ".noExl",
                name: "开票",
                filename: "开票",
                exclude_img: false,
                exclude_links: false,
                exclude_inputs: false
            });
        });

        $("#historyBack").click(function () {
            window.history.go(-1);  //返回上一页
            //window.history.back();  //返回上一页
        });
    </script>
}